﻿using System;
using System.Collections;
// using System.Collections.Generic;
using System.Text;

using MT.eVotePRS.Model;
using MT.eVotePRS.Service;
using MT.eVotePRS.Presentation.Core;

namespace MT.eVotePRS.Presentation.Logic
{
    public class ReportActions : AbstractForm
    {
        private static readonly InventoryTxnService _txnService = InventoryTxnService.GetInstance();

        public ReportActions() : base()
        {
        }

        #region Individual report
        
        public void ShowHandsetEvents(string handsetId)
        {
            IList lstHandsetTxn = InventoryTxnService.GetInstance().GetTxnByHandsetId(handsetId);

            if (lstHandsetTxn.Count > 0)
                new Util.ExcelAPIHelper().RptInvIndivHandset(lstHandsetTxn, handsetId);
        }

        public void ShowStudentEvents(string studentId)
        {
            IList lstStudentTxn = InventoryTxnService.GetInstance().GetTxnByStudentID(studentId);

            if (lstStudentTxn.Count > 0)
                new Util.ExcelAPIHelper().RptInvIndivStudent(lstStudentTxn, studentId);
        }

        #endregion


        #region Show transactions

        public void ShowHandsetEvents(Status status, DateTime from, DateTime to)
        {

            IList lstTxn = InventoryTxnService.GetInstance().GetHandsetEvents(status, from, to);
            
            if (lstTxn.Count > 0)
            {
                new Util.ExcelAPIHelper().RptInvHandsetEvents(status, lstTxn, from, to);
                return;
            }
        }

        public void ShowStudentEvents(Status status, DateTime from, DateTime to)
        {
            IList lstTxn = _txnService.GetStudentEvents(status, from, to);

            if (lstTxn != null && lstTxn.Count > 0)
            {
                new Util.ExcelAPIHelper().RptInvStudentEvents(status, lstTxn, from, to);
            }
            else
            {
                throw new Exception("No record.");
            }
        }
        #endregion
        
        #region Show report by status

        public void ShowHandsetsOnStatus(Status status)
        {
            IList lstTxn = _txnService.GetHandsetEventsByStatus(status.Id);

            if (lstTxn != null && lstTxn.Count > 0)
            {
                new Util.ExcelAPIHelper().RptInvHandsetStatus(status, lstTxn, DateTime.Now);
            }
            else
            {
                throw new Exception("No record.");
            }
        }

        public void ShowStudentsOnStatus(Status status)
        {
            IList lstTxn = _txnService.GetStudentEventsByStatus(status.Id);

            if (lstTxn.Count > 0)
            {
                new Util.ExcelAPIHelper().RptInvStudentStatus(status, lstTxn, DateTime.Now);

            }
            else
            {
                throw new Exception("No record.");
            }
        }

        #endregion

    }
}
